using System.Collections.Generic;
using Script.Data;
using UnityEngine;

public class AutoControlConfig
{
    public static List<AutoControlConfig> Confs;
    public int index;
    public int id;
    public float time;

    private static bool inited = false;

    public AutoControlConfig(List<string> conf)
    {
        conf[conf.Count - 1] = conf[conf.Count - 1].Replace("\r", "");
        index = int.Parse(conf[0]);
        id = int.Parse(conf[1]);
        time = float.Parse(conf[2]);
    }

    public static void Init()
    {
        if (inited)
        {
            return;
        }

        Confs = new List<AutoControlConfig>();
        inited = true;
        var textAsset = Resources.Load("autocontroller") as TextAsset;
        if (textAsset == null)
        {
            return;
        }

        var ret = CSVParser.LoadFromString(textAsset.text);
        for (var i = 1; i < ret.Count; i++)
        {
            Confs.Add(new AutoControlConfig(ret[i]));
        }
        Confs.Sort((a, b) => { return a.index - b.index; });
    }
}